package com.witmed.controller.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 字符编码格式的过滤器
 * @author Administrator
 *
 */ 
public class CharacterEncodingFilter implements Filter{
	
	private static String encoding;
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		encoding = filterConfig.getInitParameter("encoding");
	}
	
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		if(encoding != null) {
			// 设置请求字符编码格式
			request.setCharacterEncoding(encoding);
			// 设置响应字符编码格式
			response.setCharacterEncoding(encoding);
			// 放行
			chain.doFilter(request, response);
		}
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	

}
